package offer;

public class _05_替换空格 {
    public static void main(String[] args) {
        String s = "We are happy";
        solution solution = new _05_替换空格().new solution();
        System.out.println(solution.replaceSpace(s));
    }

    class solution {
        public String replaceSpace(String s) {
            StringBuilder sb = new StringBuilder();
            for (char c : s.toCharArray()) {
                if (c == ' ') {
                    sb.append("%20");
                } else {
                    sb.append(c);
                }
            }
            return sb.toString();
//            return s.replace(" ", "%20");
        }
    }
}
